const express = require("express");
var router = express.Router();

const redis = require("../redis/redis")
const uuidv1 = require('node-uuid');
router.get("/token", (req, res) => {
    var token = uuidv1.v1()
    redis.set(token, [])
    res.send({
        data: token,
        msg: "成功"
    })
})

/* 获取用户信息 */
router.get("/userInfo", (req, res) => {
    var { token } = req.query
    if (!token) {
        res.send({
            data: "无效参数"
        })
    } else {
        redis.get(token).then((data) => {
            res.send({
                data
            })
        })
    }
})

router.post("/asyncUserData", (req, res) => {
    var { token, data } = req.body
    redis.set(token, data)
    res.send({
        data: "同步成功"
    })
})
module.exports = router